<h3>课题申报列表</h3>
<table id="subject-list-table"></table>
<div id="subject-list-page" class="page-box"></div>
<script type="text/javascript">
    $(function () {
        getSubjectList($pageNum);
    });

    var subjectListXhr;
    function getSubjectList(pageNum) {
        if (subjectListXhr) subjectListXhr.abort();
        subjectListXhr = $.ajax({
            url: "/api/subject/list",
            type: "get",
            data: "page_num=" + pageNum,
            dataType: "json",
            beforeSend: function() {
            },
            complete: function() {
            },
            success: function (result) {
                if (result.code == 200) {
                    var data = result.data;
                    var list = data.list;

                    var tr = "";
                    for (x in list) {
                        tr += '<tr data-id="' + list[x].id + '">'
                            + '<td class="name">' + list[x].name + '</td>'
                            + '<td class="user-realname">' + list[x].user.realname + '</td>'
                            + '<td class="classification">' + list[x].classification.desc + '</td>'
                            + '<td class="state">' + list[x].state.desc + '</td>'
                            + '<td>' + initOperate(list[x].id,list[x].state,list[x].can_approval) + '</td>'
                            + '</tr>';
                    }

                    var headTr = '<tr>'
                        + '<th>标题</th>'
                        + '<th>支持人</th>'
                        + '<th>学科</th>'
                        + '<th>进度</th>'
                        + '<th>操作</th>'
                        + '</tr>';
                    $("#subject-list-table").html(headTr + tr);

                    initPage($("#subject-list-page"), data, getSubjectList);
                }
            },error: function (result) {

            }
        });
    }
    
    function initOperate(id,state,canApproval) {
        switch (state.value) {
            case 4:
                return '<a data-url="/subject/' + id + '/show/main" onclick="openPage(this)">浏览</a>'
                    + '<a data-url="/subject/' + id + '/check/returnback" onclick="openPage(this)">退回</a>'
                    + '<a data-url="/subject/' + id + '/check/appoint" onclick="openPage(this)">指派专家</a>';
            case 5:
                if (canApproval == true) {
                    return '<a data-url="/subject/' + id + '/show/main" onclick="openPage(this)">浏览</a>'
                        + '<a data-url="/subject/' + id + '/check/approval" onclick="openPage(this)">立项审核</a>';
                } else if (canApproval == false) {
                    return '<a data-url="/subject/' + id + '/show/main" onclick="openPage(this)">浏览</a>'
                        + '<a data-url="/subject/' + id + '/check/approval" onclick="openPage(this)">重新修改</a>'; // 已退回该课题申报书让申报人修改!
                }
            default:
                return '<a data-url="/subject/' + id + '/show/main" onclick="openPage(this)">浏览</a>'
                    + '<span>等待审核</span>';
        }
    }
</script>